import { ref } from 'vue'

import { menuApi } from '@/apis'

export function useMenuTree() {
  const menuTree = ref([] as ITreeNode[])
  const treeLoading = ref(false)

  async function getMenuTree() {
    treeLoading.value = true

    const data = await menuApi.getMenuTree()
    menuTree.value = [{ key: '0', title: '主类目', children: data }]

    treeLoading.value = false
  }

  return {
    menuTree,
    treeLoading,
    getMenuTree
  }
}
